﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Edu.ZJ
{
    public partial class SwitchSiteForm : Form
    {
        public SwitchSiteForm(string code)
        {
            InitializeComponent();

            SiteCode = code;
            Init();
        }

        private void Init()
        {
            var list = SiteUtil.GetSiteList();

            int top = 0;
            RadioButton[] btns = new RadioButton[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                var site = list[i];
                btns[i] = new RadioButton();
                top = (i + 1) * 6;
                if (i > 0)
                {
                    top += 21;
                }

                btns[i].AutoCheck = true;
                btns[i].AutoSize = true;
                btns[i].Top = top;
                btns[i].Location = new Point(20, top);
                btns[i].Text = site.ToString();
                btns[i].Checked = SiteCode == site.Code;
                btns[i].Visible = true;
                btns[i].Name = $"radioBtn{i}";
                btns[i].Tag = site.Code;
                btns[i].CheckedChanged += SwitchSiteForm_CheckedChanged;
                this.panel1.Controls.Add(btns[i]);
            }
        }

        private void SwitchSiteForm_CheckedChanged(object sender, EventArgs e)
        {
            var radioBtn = (RadioButton)sender;
            this.SiteCode = radioBtn.Tag.ToString();
        }

        public string SiteCode { get; set; }
    }
}
